package ctrl;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import chat.single.MsgSing;
import chat.user.UserBean;

public class ChatMsgSendCtrl extends HttpServlet {
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		
		String path = req.getContextPath();
		
		String content = req.getParameter("content");
		
		HttpSession s = req.getSession();
		
		UserBean user = (UserBean) s.getAttribute("userBean");
		
		//异常测试
//		user = null;
//		System.out.println(user.getName());
		
		MsgSing.getIns().addMsg(user, content);
		
		resp.sendRedirect(path+"/page/ChatViewCtrl.php");
	}

}